package com.example.shuiyin.dto;

import com.example.shuiyin.entity.FileInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FileInfoDTO {
    private Long id;
    private String fileId;
    private String fileName;
    private String originalName;
    private String contentType;
    private Long fileSize;
    private String filePath;
    private String url;
    private String thumbnailUrl;
    private String status;
    private Long userId;
    private LocalDateTime uploadTime;
    private LocalDateTime lastAccessTime;
    private LocalDateTime updatedAt;
    
    /**
     * 从实体对象转换为DTO
     */
    public static FileInfoDTO fromEntity(FileInfo fileInfo) {
        if (fileInfo == null) {
            return null;
        }
        
        return FileInfoDTO.builder()
                .id(fileInfo.getId())
                .fileId(fileInfo.getFileId())
                .fileName(fileInfo.getFileName())
                .originalName(fileInfo.getOriginalName())
                .contentType(fileInfo.getContentType())
                .fileSize(fileInfo.getFileSize())
                .filePath(fileInfo.getFilePath())
                .url(fileInfo.getUrl())
                .thumbnailUrl(fileInfo.getThumbnailUrl())
                .status(fileInfo.getStatus())
                .userId(fileInfo.getUserId())
                .uploadTime(fileInfo.getUploadTime())
                .lastAccessTime(fileInfo.getLastAccessTime())
                .updatedAt(fileInfo.getUpdatedAt())
                .build();
    }
} 